using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DialogBase : MonoBehaviour
{
    [SerializeField] protected Animator dialogAnimator;
    [SerializeField] protected string dialogIntroTrigger = "Intro";
    [SerializeField] protected string dialogOutroTrigger = "Outro";
    
    private float timeToDestroy = 0.3f;

    public void OpenDialog()
    {
        dialogAnimator = GetComponent<Animator>();
        if (!gameObject.activeSelf)
        {
            gameObject.SetActive(true);
        }
        dialogAnimator.SetTrigger(dialogIntroTrigger);
    }
    
    public virtual void CloseDialog()
    {
        dialogAnimator.SetTrigger(dialogOutroTrigger);
        StartCoroutine(DestroyDialog());
    }

    private IEnumerator DestroyDialog()
    {
        yield return new WaitForSecondsRealtime(timeToDestroy);
        Destroy(gameObject);
    }
}
